<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title>超市账单管理系统</title>
    <link rel="stylesheet" href="/statics/css/public.css"/>
    <link rel="stylesheet" href="/statics/css/style.css"/>
    <script type="text/javascript" src="/statics/js/jquery.js"></script>
    <script type="text/javascript">
        $(function () {
            //失去焦点事件
            $("#proCode").blur(function () {
               //获取供应商编号
                var code=$(this).val();
                if(code=='' || code.length<=0){
                    $("#proCode").next().html("供应商编号不能为空");
                    $("#proCode").focus();
                    return;
                }
                $.get("/sys/provider/check","code="+code,function (result) {
                   if(result=='error'){
                       //供应商编号重复
                       $("#proCode").next().html("供应商编号重复，请重新设置");
                       $("#proCode").focus();
                   }else{
                       //没有重复
                       $("#proCode").next().html("<img src='/statics/img/xg.png'>");
                   }
                });
            });
            //添加按钮单击事件
            $("#saveButton").click(function () {
                //表单验证
                if(check()){
                    //获取表单数据
                    var data=$("form").serialize();
                    //ajax请求
                    $.post("/sys/provider/save",data,function (result) {
                        if(result=='success'){
                            alert("添加供应商信息成功");
                            location.href="/sys/provider/toList";
                        }else{
                            alert("添加供应商信息失败，请稍后再试");
                        }

                    })
                }
            });
        });
        //添加供应商信息的非空验证
        function check() {
            //供应商名称必填
            var proName=$("#proName").val();
            if(proName==''){
                $("#proName").next().html("供应商名称不能为空");
                return false;
            }else{
                $("#proName").next().html("<img src='/statics/img/xg.png'>");
            }
            //联系人必填
            var proContact=$("#proContact").val();
            if(proContact==''){
                $("#proContact").next().html("联系人不能为空");
                return false;
            }else{
                $("#proContact").next().html("<img src='/statics/img/xg.png'>");
            }
            //联系电话必填
            var proPhone=$("#proPhone").val();
            if(proPhone==''){
                $("#proPhone").next().html("联系电话不能为空");
                return false;
            }else{
                $("#proPhone").next().html("<img src='/statics/img/xg.png'>");
            }
            return true;
        }
    </script>
</head>
<body>
<section class="publicMian ">
    <div class="right">
        <div class="location">
            <strong>你现在所在的位置是:</strong>
            <span>供应商管理页面 >> 供应商添加页面</span>
        </div>
        <div class="providerAdd">
            <form>
                <!--div的class 为error是验证错误，ok是验证成功-->
                <div class="">
                    <label for="proCode">供应商编码：</label>
                    <input type="text" name="proCode" id="proCode"/>
                    <span>*请输入供应商编码</span>
                </div>
                <div>
                    <label for="proName">供应商名称：</label>
                    <input type="text" name="proName" id="proName"/>
                    <span >*请输入供应商名称</span>
                </div>
                <div>
                    <label for="proContact">联系人：</label>
                    <input type="text" name="proContact" id="proContact"/>
                    <span>*请输入联系人</span>

                </div>
                <div>
                    <label for="proPhone">联系电话：</label>
                    <input type="text" name="proPhone" id="proPhone"/>
                    <span>*请输入联系电话</span>
                </div>
                <div>
                    <label for="proAddress">联系地址：</label>
                    <input type="text" name="proAddress" id="proAddress"/>
                    <span></span>
                </div>
                <div>
                    <label for="proFax">传真：</label>
                    <input type="text" name="proFax" id="proFax"/>
                    <span></span>
                </div>
                <div>
                    <label for="proDesc">描述：</label>
                    <input type="text" name="proDesc" id="proDesc"/>
                </div>
                <div class="providerAddBtn">
                    <!--<a href="#">保存</a>-->
                    <!--<a href="providerList.html">返回</a>-->
                    <input type="button" value="保存" id="saveButton"/>
                    <input type="button" value="返回" onclick="history.back(-1)"/>
                </div>
            </form>
        </div>

    </div>
</section>

</body>
</html>
